<?php
namespace app\mobile\controller;

use app\model\Theme; 
use app\model\Worker; 

class WInitAgent extends Base
{
    public function W_init_agent()
    {
global $_G, $_P;
$do='w_init_agent';
$op = !empty($_P['op']) ? $_P['op'] : 'display';
$system = $_G['system'];
$fans = $this->checkuser();
$themeid = intval($_P['themeid']);
if ($themeid < 0) {
    return_msg('管理后台地址不正确');
}
$theme = Theme::getThemeById($themeid);
$config = Theme::getConfig($themeid);

$result = Worker::w_init_agent($system,$theme,$config,$fans,$op);
if ($result['error']==1){
    return_msg($result['msg']);
}
if ($result['error']==2){
    //进入活动链接
    $sharedata = array(
        'themeid'=>$themeid,
        'fopenid'=>$_G['openid'],
        'fromuid'=>$_G['member']['uid'],
        'workerid'=>$_G['member']['uid'],
    );
    if ($system['gongzhong'] =='1'){
        $domaintxt = $system['domainhead1'];
    }else{
        $domaintxt = DOMAIN0;
    }
    $tourl = $_G['url_scheme'].$domaintxt."/".createMobileUrl('index',$sharedata);
    echo "<script language='javascript' type='text/javascript'>";
    echo "window.location.href='$tourl';";
    echo "</script>";
    exit;
}

$superior_info = $result['superior_info'];

$return_clicent = get_defined_vars();
return view('/fcworker/fc_init_agent' , $return_clicent);
}
}